﻿#ifndef _OI_HASP_API_HPP_
#define _OI_HASP_API_HPP_

#if !defined(WITH_AKSTYPES) && !defined(WITH_OEFTYPES)
#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)
typedef unsigned __int64 hasp_u64_t;
typedef signed __int64 hasp_s64_t;
#else
typedef unsigned long long hasp_u64_t;
typedef signed long long hasp_s64_t;
#endif
#if defined(_MSC_VER)
typedef unsigned long hasp_u32_t;
typedef signed long hasp_s32_t;
#else
typedef unsigned int hasp_u32_t;
typedef signed int hasp_s32_t;
#endif
typedef unsigned short hasp_u16_t;
typedef signed short hasp_s16_t;
typedef signed char hasp_s8_t;
typedef unsigned char hasp_u8_t;
#endif

namespace Hasp_Api
{
/**
 * @defgroup hasp_feature_ids Legacy HASP HL Run-time API: Feature ID defines
 *
 * @{
 */

/**
 * \brief Legacy HASP HL Run-time API: "Feature Type" mask
 *
 * AND-mask used to identify Feature type.
 */
#define HASP_FEATURETYPE_MASK 0xffff0000

/**
 * \brief Legacy HASP HL Run-time API: "Program Number Feature" type
 *
 * After AND-ing with HASP_FEATURETYPE_MASK the Feature type contain this value.
 */
#define HASP_PROGNUM_FEATURETYPE 0xffff0000

/**
 * \brief Legacy HASP HL Run-time API: "Program Number Mask"
 *
 * AND-mask used to extract the Program Number from a
 * "prognum" Feature ID.
 */
#define HASP_PROGNUM_MASK 0x000000ff

/**
 * \brief Legacy HASP HL Run-time API: "Program Number Options" mask
 *
 * AND-mask used to identify Program Number options:
 *   <ul>
 *     <li>HASP_PROGNUM_OPT_NO_LOCAL</li>
 *     <li>HASP_PROGNUM_OPT_NO_REMOTE</li>
 *     <li>HASP_PROGNUM_OPT_PROCESS</li>
 *     <li>HASP_PROGNUM_OPT_CLASSIC</li>
 *     <li>HASP_PROGNUM_OPT_TS</li>
 *   </ul>
 *
 * 3 bits of the mask are reserved for future extensions and currently unused.
 * Initialize them with zero.
 */
#define HASP_PROGNUM_OPT_MASK 0x0000ff00

/**
 * \brief Legacy HASP HL Run-time API: "Program Number" option
 *
 * Disables the search for local licenses.
 */
#define HASP_PROGNUM_OPT_NO_LOCAL 0x00008000

/**
 * \brief Legacy HASP HL Run-time API: "Program Number" option
 *
 * Disables the search for network licenses.
 */
#define HASP_PROGNUM_OPT_NO_REMOTE 0x00004000

/**
 * \brief Legacy HASP HL Run-time API: "Program Number" option
 *
 * Sets session count of network licenses to "per-process".
 */
#define HASP_PROGNUM_OPT_PROCESS 0x00002000

/**
 * \brief Legacy HASP HL Run-time API: "Program Number" option
 *
 * Enables the API to access "classic" (HASP4 or earlier) keys.
 */
#define HASP_PROGNUM_OPT_CLASSIC 0x00001000

/**
 * \brief Legacy HASP HL Run-time API: "Program Number" option
 *
 * Ignores the presence of terminal servers.
 */
#define HASP_PROGNUM_OPT_TS 0x00000800

/**
 * \brief The Sentinel default Feature ID
 *
 * Available in every Sentinel key.
 */
#define HASP_DEFAULT_FID 0

/**
 * \brief Legacy HASP HL Run-time API: The HASP default Feature ID
 *
 * Available in every legacy HASP hardware key.
 */
#define HASP_PROGNUM_DEFAULT_FID (HASP_DEFAULT_FID | HASP_PROGNUM_FEATURETYPE)

/**
 * @}
 */



/**
 * @defgroup hasp_file_ids Memory File ID defines
 *
 * @{
 */

/**
 * \brief Legacy HASP HL Run-time API: HASP4 memory file
 *
 * File ID for HASP4-compatible memory contents w/o FAS.
 */
#define HASP_FILEID_MAIN 0xfff0

/**
 * \brief Legacy HASP HL Run-time API: HASP4 FAS memory file
 *
 * (Dummy) File ID for the license data area of memory contents.
 */
#define HASP_FILEID_LICENSE 0xfff2

/**
 * \brief Sentinel secure writable memory file
 *
 * File ID for Sentinel secure writable memory.
 */
#define HASP_FILEID_RW 0xfff4

/**
 * \brief Sentinel secure read only memory file
 *
 * File ID for Sentinel read only memory.
 */
#define HASP_FILEID_RO 0xfff5

/**
 * \brief Sentinel dynamic memory file ID avaliable range
 *
 * File ID lower limit for Sentinel dynamic memory file.
 */
#define HASP_FILEID_DYNAMIC_FIRST 0x1

/**
 * \brief Sentinel dynamic memory file ID avaliable range
 *
 * File ID upper limit for Sentinel dynamic memory file.
 */
#define HASP_FILEID_DYNAMIC_LAST 0xffbf

/**
 * @}
 */

/**
 * @defgroup hasp_error_codes Run-time API Status Codes
 *
 * @{
 */




enum hasp_error_codes
{
    LOAD_DLL_FAILED = -1,

    /** Request successfully completed */
    HASP_STATUS_OK = 0,

    /** Request exceeds memory range of a Sentinel file */
    HASP_MEM_RANGE = 1,

    /** Legacy HASP HL Run-time API: Unknown/Invalid Feature ID option */
    HASP_INV_PROGNUM_OPT = 2,

    /** System is out of memory */
    HASP_INSUF_MEM = 3,

    /** Too many open Features/login sessions */
    HASP_TMOF = 4,

    /** Access to Feature, Sentinel protection key or functionality denied */
    HASP_ACCESS_DENIED = 5,

    /** Legacy decryption function cannot work on Feature */
    HASP_INCOMPAT_FEATURE = 6,

    /** Sentinel protection key not available */
    HASP_HASP_NOT_FOUND = 7,

    /* Deprecated - use HASP_HASP_NOT_FOUND */
    HASP_CONTAINER_NOT_FOUND = 7,

    /** Encrypted/decrypted data length too short to execute function call */
    HASP_TOO_SHORT = 8,

    /** Invalid login handle passed to function */
    HASP_INV_HND = 9,

    /** Specified File ID not recognized by API */
    HASP_INV_FILEID = 10,

    /** Installed driver or daemon too old to execute function */
    HASP_OLD_DRIVER = 11,

    /** Real-time clock (rtc) not available */
    HASP_NO_TIME = 12,

    /** Generic error from host system call */
    HASP_SYS_ERR = 13,

    /** Required driver not installed */
    HASP_NO_DRIVER = 14,

    /** Invalid XML format */
    HASP_INV_FORMAT = 15,

    /** Unable to execute function in this context; the requested
     * functionality is not implemented */
    HASP_REQ_NOT_SUPP = 16,

    /** Binary data passed to function does not contain valid update */
    HASP_INV_UPDATE_OBJ = 17,

    /** Sentinel protection key not found */
    HASP_KEYID_NOT_FOUND = 18,

    /** Required XML tags not found; Contents in binary data are missing
     * or invalid */
    HASP_INV_UPDATE_DATA = 19,

    /** Update request not supported by Sentinel protection key */
    HASP_INV_UPDATE_NOTSUPP = 20,

    /** Update counter set incorrectly */
    HASP_INV_UPDATE_CNTR = 21,

    /** Invalid Vendor Code passed */
    HASP_INV_VCODE = 22,

    /** Sentinel protection key does not support encryption type */
    HASP_ENC_NOT_SUPP = 23,

    /** Passed time value outside supported value range */
    HASP_INV_TIME = 24,

    /** Real-time clock battery out of power */
    HASP_NO_BATTERY_POWER = 25,

    /** Acknowledge data requested by update, but ack_data parameter
     * is NULL */
    HASP_NO_ACK_SPACE = 26,

    /** Program running on a terminal server */
    HASP_TS_DETECTED = 27,

    /** Program running on a Remote Desktop */
    HASP_RDP_DETECTED = 27,

    /** Requested Feature type not implemented */
    HASP_FEATURE_TYPE_NOT_IMPL = 28,

    /** Unknown algorithm used in H2R/V2C file */
    HASP_UNKNOWN_ALG = 29,

    /** Signature verification operation failed */
    HASP_INV_SIG = 30,

    /** Requested Feature not available */
    HASP_FEATURE_NOT_FOUND = 31,

    /** Access log not enabled */
    HASP_NO_LOG = 32,

    /** Communication error between API and local Sentinel License Manager */
    HASP_LOCAL_COMM_ERR = 33,

    /** Vendor Code not recognized by API */
    HASP_UNKNOWN_VCODE = 34,

    /** Invalid XML specification */
    HASP_INV_SPEC = 35,

    /** Invalid XML scope */
    HASP_INV_SCOPE = 36,

    /** Too many Sentinel protection keys match the scope */
    HASP_TOO_MANY_KEYS = 37,

    /** Too many concurrent user sessions currently connected */
    HASP_TOO_MANY_USERS = 38,

    /** Session been interrupted */
    HASP_BROKEN_SESSION = 39,

    /** Communication error between local and remote Sentinel License Managers */
    HASP_REMOTE_COMM_ERR = 40,

    /** Feature expired */
    HASP_FEATURE_EXPIRED = 41,

    /** Sentinel License Manager version too old */
    HASP_OLD_LM = 42,

    /** Input/Output error occurred in secure storage area of Sentinel SL key OR
     * a USB error occurred when communicating with a Sentinel HL key */
    HASP_DEVICE_ERR = 43,

    /** Update installation not permitted; This update was already applied */
    HASP_UPDATE_BLOCKED = 44,

    /** System time has been tampered with */
    HASP_TIME_ERR = 45,

    /** Communication error occurred in secure channel */
    HASP_SCHAN_ERR = 46,

    /** Corrupt data exists in secure storage area of Sentinel SL protection key */
    HASP_STORAGE_CORRUPT = 47,

    /** Unable to find Vendor library */
    HASP_NO_VLIB = 48,

    /** Unable to load Vendor library */
    HASP_INV_VLIB = 49,

    /** Unable to locate any Feature matching scope */
    HASP_SCOPE_RESULTS_EMPTY = 50,

    /** Program running on a virtual machine */
    HASP_VM_DETECTED = 51,

    /** Sentinel SL key incompatible with machine hardware; Sentinel SL key is locked
     * to different hardware. OR:
     * In the case of a V2C file, conflict between Sentinel SL key data and machine
     * hardware data; Sentinel SL key locked to different hardware */
    HASP_HARDWARE_MODIFIED = 52,

    /** Login denied because of user restrictions */
    HASP_USER_DENIED = 53,

    /** Trying to install a V2C file with an update counter that is out of
     * sequence with the update counter on the Sentinel protection key.
     * The update counter value in the V2C file is lower than the value in
     * Sentinel protection key. */
    HASP_UPDATE_TOO_OLD = 54,

    /** Trying to install a V2C file with an update counter that is out of
     * sequence with update counter in the Sentinel protection key. The
     * first value in the V2C file is greater than the value in the
     * Sentinel protection key. */
    HASP_UPDATE_TOO_NEW = 55,

    /** Vendor library version too old */
    HASP_OLD_VLIB = 56,

    /** Upload via ACC failed, e.g. because of illegal format */
    HASP_UPLOAD_ERROR = 57,

    /** Invalid XML "recipient" parameter */
    HASP_INV_RECIPIENT = 58,

    /** Invalid XML "action" parameter */
    HASP_INV_ACTION = 59,

    /* Deprecated - use HASP_INV_ACTION */
    HASP_INV_DETACH_ACTION = 59,

    /** Scope does not specify a unique Product */
    HASP_TOO_MANY_PRODUCTS = 60,

    /** Invalid Product information */
    HASP_INV_PRODUCT = 61,

    /** Unknown Recipient; update can only be applied to the
     * Recipient specified in hasp_detach(), and not to this computer */
    HASP_UNKNOWN_RECIPIENT = 62,

    /** Invalid duration */
    HASP_INV_DURATION = 63,

    /** Cloned Sentinel SL secure storage detected */
    HASP_CLONE_DETECTED = 64,

    /** Specified V2C update already installed in the LLM */
    HASP_UPDATE_ALREADY_ADDED = 65,

    /** Specified Hasp Id is in Inactive state */
    HASP_HASP_INACTIVE = 66,

    /** No detachable feature exists */
    HASP_NO_DETACHABLE_FEATURE = 67,

    /** No detachable feature exists (typo kept for compatibility */
    HASP_NO_DEATCHABLE_FEATURE = 67,

    /** Scope does not specify a unique host */
    HASP_TOO_MANY_HOSTS = 68,

    /** Rehost is not allowed for any license */
    HASP_REHOST_NOT_ALLOWED = 69,

    /** License is rehosted to other machine */
    HASP_LICENSE_REHOSTED = 70,

    /** Old rehost license try to apply */
    HASP_REHOST_ALREADY_APPLIED = 71,

    /** File not found or access denied */
    HASP_CANNOT_READ_FILE = 72,

    /** Extension of license not allowed as number of detached
     * licenses is greater than current concurrency count */
    HASP_EXTENSION_NOT_ALLOWED = 73,

    /** Detach of license not allowed as product
     * contains VM disabled feature and host machine is a virtual machine */
    HASP_DETACH_DISABLED = 74,

    /** Rehost of license not allowed as container
     * contains VM disabled feature and host machine is a virtual machine */
    HASP_REHOST_DISABLED = 75,

    /** Format SL-AdminMode or migrate SL-Legacy to SL-AdminMode not allowed
     * as container has detached license */
    HASP_DETACHED_LICENSE_FOUND = 76,

    /** Recipient of the requested operation is older than expected */
    HASP_RECIPIENT_OLD_LM = 77,

    /** Secure storage ID mismatch */
    HASP_SECURE_STORE_ID_MISMATCH = 78,

    /** Duplicate Hostname found while key contains Hostname Fingerprinting */
    HASP_DUPLICATE_HOSTNAME = 79,

    /** The Sentinel License Manager is required for this operation */
    HASP_MISSING_LM = 80,

    /** You are attempting to consume multiple executions during log in to a Feature.
     * However, the license for the Feature does not contain enough remaining executions */
    HASP_FEATURE_INSUFFICIENT_EXECUTION_COUNT = 81,

    /** API dispatcher: API for this Vendor Code was not found */
    HASP_NO_API_DYLIB = 400,

    /** API dispatcher: Unable to load API; DLL possibly corrupt? */
    HASP_INV_API_DYLIB = 401,

    /** Invalid function parameter */
    HASP_INVALID_PARAMETER = 501,

    /** C++ API: Object incorrectly initialized */
    HASP_INVALID_OBJECT = 500,

    /** C++ API: Logging in twice to the same object */
    HASP_ALREADY_LOGGED_IN = 502,

    /** C++ API: Logging out twice of the same object */
    HASP_ALREADY_LOGGED_OUT = 503,

    /** .NET API: Incorrect use of system or platform */
    HASP_OPERATION_FAILED = 525,

    /* Internal use: no classic memory extension block available */
    HASP_NO_EXTBLOCK = 600,

    /* Internal use: invalid port type */
    HASP_INV_PORT_TYPE = 650,

    /* Internal use: invalid port value */
    HASP_INV_PORT = 651,

    /* Dot-Net DLL found broken */
    HASP_NET_DLL_BROKEN = 652,

    /** Requested function not implemented */
    HASP_NOT_IMPL = 698,

    /** Internal error occurred in API */
    HASP_INT_ERR = 699,

    /* Reserved for Sentinel helper libraries */
    HASP_FIRST_HELPER = 2001,

    /* Reserved for Sentinel Activation API */
    HASP_FIRST_HASP_ACT = 3001,

    HASP_NEXT_FREE_VALUES = 7001,
};

/**
 * @}
 */



/**
 * @defgroup hasp_general Sentinel typedefs and macros
 *
 * @{
 */

/** A Sentinel status code */
typedef enum hasp_error_codes hasp_status_t;

/** Sentinel size type */
typedef hasp_u32_t hasp_size_t;

/** Sentinel connection handle */
typedef hasp_u32_t hasp_handle_t;

/** Sentinel Feature ID */
typedef hasp_u32_t hasp_feature_t;

/** Sentinel File ID */
typedef hasp_u32_t hasp_fileid_t;

/** Sentinel timestamp, representing elapsed seconds since
 * Jan-01-1970 0:00:00 GMT */
typedef hasp_u64_t hasp_time_t;

/** Sentinel Vendor Code buffer */
typedef const void *hasp_vendor_code_t;


/** format to retrieve update info (C2V) */
#define HASP_UPDATEINFO     "<haspformat format=\"updateinfo\"/>"

/* format to retrieve a small update info (C2V) */
#define HASP_FASTUPDATEINFO "<haspformat format=\"fastupdateinfo\"/>"

/** format to retrieve session info */
#define HASP_SESSIONINFO    "<haspformat format=\"sessioninfo\"/>"

/** format to retrieve key/hardware info */
#define HASP_KEYINFO        "<haspformat format=\"keyinfo\"/>"

/** format to retrieve host fingerprint info */
#define HASP_FINGERPRINT    "<haspformat format=\"host_fingerprint\"/>"

/** format to retrieve recipient parameter for hasp_transfer */
#define HASP_RECIPIENT      "<haspformat root=\"location\">"             \
                            "  <license_manager>"                        \
                            "    <attribute name=\"id\" />"              \
                            "    <attribute name=\"time\" />"            \
                            "    <element name=\"hostname\" />"          \
                            "    <element name=\"version\" />"           \
                            "    <element name=\"host_fingerprint\" />"  \
                            "  </license_manager>"                       \
                            "</haspformat>"

/*
 * Invalid handle value for hasp_login() and hasp_login_scope() functions.
 */
#define HASP_INVALID_HANDLE_VALUE 0

/**
 * \brief Minimum block size for hasp_encrypt() and hasp_decrypt() functions.
 */
#define HASP_MIN_BLOCK_SIZE 16

/**
 * \brief Minimum block size for hasp_legacy_encrypt()
 *        and hasp_legacy_decrypt() legacy functions.
 */
#define HASP_MIN_BLOCK_SIZE_LEGACY 8

/**
 * @}
 */



/**
 * @defgroup hasp_basic The Basic Sentinel Licensing API
 *
 * @{
 */

/**
 * \brief Logs into a Feature and thereby establishes a session context.
 *
 * <b>Sentinel Licensing API Usage Notes</b><br>
 * This function establishes a context to a Sentinel protection key
 * containing a license for the requested Feature ID.
 *
 * The requisite Vendor Codes are stored in a VendorCodes folder in your
 * system. Without the correct Vendor Code, the function call cannot succeed.
 *
 * You can open up to 512 simultaneous login sessions.
 *
 * <b>Legacy HASP Remarks</b><br>
 * For local prognum Features, concurrency is not handled and each login
 * performs a decrement if it is a counting license.
 *
 * Network "prognum" features continue to use the old HASP/Sentinel LM login logic,
 * with its inherent limitations.
 *
 * There is only support for concurrent usage of <b>one</b> server (global
 * server address).
 *
 * With "Program Number" features (see \ref HASP_FEATURETYPE_MASK), 8
 * bits are reserved for legacy options (see \ref HASP_PROGNUM_OPT_MASK,
 * currently 5 bits are used):
 * <ul>
 *   <li>only local</li>
 *   <li>only remote</li>
 *   <li>login is counted per process ID</li>
 *   <li>disable terminal server check</li>
 *   <li>enable access to old (HASP3/HASP4) keys</li>
 * </ul>
 *
 * \param feature_id  Unique identifier for a specific Feature stored
 *                    in a Sentinel protection key
 * \param vendor_code Pointer to the Vendor Code
 * \param handle      Pointer to the resulting session handle
 *
 * \return            <ul>
 *                      <li>HASP_STATUS_OK</li> Request was successfully
 *                        completed
 *                      <li>HASP_HASP_NOT_FOUND</li> Required Sentinel
 *                        protection key not found
 *                      <li>HASP_FEATURE_NOT_FOUND</li> Cannot find requested
 *                        Feature
 *                      <li>HASP_FEATURE_TYPE_NOT_IMPL</li> Requested Feature
 *                        type not available
 *                      <li>HASP_TMOF</li> Too many open login sessions
 *                      <li>HASP_INSUF_MEM</li> Out of memory
 *                      <li>HASP_INV_VCODE</li> Invalid Vendor Code
 *                      <li>HASP_NO_DRIVER</li> Driver not installed
 *                      <li>HASP_NO_VLIB</li> Vendor library cannot be found
 *                      <li>HASP_INV_VLIB</li> Vendor library cannot be loaded
 *                      <li>HASP_OLD_DRIVER</li> Driver too old
 *                      <li>HASP_UNKNOWN_VCODE</li> Vendor Code not recognized
 *                      <li>HASP_FEATURE_EXPIRED</li> Feature has expired
 *                      <li>HASP_TOO_MANY_USERS</li> Too many users currently
 *                        connected
 *                      <li>HASP_OLD_LM</li> Sentinel License Manager version
 *                        too old
 *                      <li>HASP_DEVICE_ERR</li> Input/Output error in  Sentinel
 *                        SL/SL-AdminMode/SL-UserMode secure storage, OR in
 *                        case of a Sentinel HL key, USB communication error
 *                      <li>HASP_TIME_ERR</li> System time has been tampered
 *                        with
 *                      <li>HASP_HARDWARE_MODIFIED</li> Sentinel SL key
 *                        incompatible with machine hardware; Sentinel SL key is
 *                        locked to different hardware
 *                      <li>HASP_TS_DETECTED</li> Program is running on a
 *                        Terminal Server
 *                      <li>HASP_LOCAL_COMM_ERR</li> Communication error
 *                        between API and local  Sentinel License Manager
 *                      <li>HASP_REMOTE_COMM_ERR</li> Communication error
 *                        between local and remote  Sentinel License Manager
 *                      <li>HASP_OLD_VLIB</li> Vendor Library version too old
 *                      <li>HASP_CLONE_DETECTED</li> Cloned Sentinel SL storage
 *                        detected. Feature unavailable
 *                    </ul>
 *
 * \sa hasp_login_scope()
 * \sa hasp_logout()
 *
 */

//         typedef bool(*SetPortsFunc)( uint16_t val );

hasp_status_t hasp_login(hasp_feature_t feature_id,
    hasp_vendor_code_t vendor_code,
    hasp_handle_t *handle);



/**
 * \brief Logs out from a context or session.
 *
 * <b>Sentinel Licensing API Usage Notes</b><br>
 * Use this function to end a connection to an API session object. Once
 * logged out from a session, all memory allocated for the session is released.
 *
 * \param handle      Handle for the session being terminated
 *
 * \return            <ul>
 *                      <li>HASP_STATUS_OK</li> Request was successfully
 *                        completed
 *                      <li>HASP_INV_HND</li> Invalid input handle
 *                      <li>HASP_LOCAL_COMM_ERR</li> Communication error
 *                        between API and local Sentinel License Manager
 *                      <li>HASP_REMOTE_COMM_ERR</li> Communication error
 *                        between local and remote Sentinel License Manager
 *                    </ul>
 *
 * \sa hasp_login()
 * \sa hasp_login_scope()
 *
 */
hasp_status_t hasp_logout(hasp_handle_t handle);


/**
 * \brief Reads the memory of a Sentinel protection key.
 *
 * <b>Sentinel Licensing API Usage Notes</b><br>
 * Valid File IDs are \ref HASP_FILEID_RW and \ref HASP_FILEID_RO.
 * From Sentinel LDK 7.1, Sentinel HL Driverless keys support dynamic memory,
 * the File IDs can be from HASP_FILEID_DYNAMIC_FIRST(0x1) to HASP_FILEID_DYNAMIC_LAST(0xFFBF).
 *
 * <b>Legacy HASP Remarks</b><br>
 * Valid File IDs are \ref HASP_FILEID_LICENSE and \ref HASP_FILEID_MAIN.
 *
 * \param handle      Handle for the session
 * \param fileid      Identifier for the file that is to be read
 * \param offset      Byte offset in the file
 * \param length      Number of bytes to be read from the file
 * \param buffer      Pointer to the retrieved data
 *
 * \return            <ul>
 *                      <li>HASP_STATUS_OK</li> Request was successfully
 *                        completed
 *                      <li>HASP_INV_HND</li> Invalid input handle
 *                      <li>HASP_INV_FILEID</li> Unrecognized file identifier
 *                      <li>HASP_MEM_RANGE</li> Request exceeds the memory
 *                        range of a Sentinel file
 *                      <li>HASP_DEVICE_ERR</li> Input/Output error in Sentinel
 *                        SL/SL-AdminMode/SL-UserMode secure storage, OR in
 *                        case of a Sentinel HL key, USB communication error
 *                      <li>HASP_SCHAN_ERR</li> Communication error occurred
 *                        in secure channel OR Sentinel HL Firmware too old
 *                        (update to 3.25 or later)
 *                      <li>HASP_BROKEN_SESSION</li> Session has been
 *                        interrupted
 *                      <li>HASP_LOCAL_COMM_ERR</li> Communication error
 *                        between API and local Sentinel License Manager
 *                      <li>HASP_REMOTE_COMM_ERR</li> Communication error
 *                        between local and remote Sentinel License Manager
 *                    </ul>
 *
 * \remark
 * Use the \ref hasp_get_size function to determine the size of the file you
 * want to read.
 *
 * \sa hasp_write()
 * \sa hasp_get_size()
 *
 */
hasp_status_t hasp_read(hasp_handle_t handle,
                hasp_fileid_t fileid,
                hasp_size_t offset,
                hasp_size_t length,
                void *buffer);

/**
 * \brief Writes to the memory of a Sentinel protection key.
 *
 * <b>Sentinel Licensing API Usage Notes</b><br>
 * Valid File ID is \ref HASP_FILEID_RW.
 * From Sentinel LDK 7.1, Sentinel HL Driverless keys support dynamic memory,
 * the File IDs can be from HASP_FILEID_DYNAMIC_FIRST(0x1) to HASP_FILEID_DYNAMIC_LAST(0xFFBF).
 *
 * <b>Legacy HASP Remarks</b><br>
 * Depending on the provided session handle (either logged into the
 * default Feature or any other Feature), write access to the FAS memory
 * (\ref HASP_FILEID_LICENSE) is not permitted.
 *
 * \param handle      Handle for the session
 * \param fileid      Identifier for the file that is to be written
 * \param offset      Byte offset in the file
 * \param length      Number of bytes to be written to the file
 * \param buffer      Pointer to the data
 *
 * \return            <ul>
 *                      <li>HASP_STATUS_OK</li> Request was successfully
 *                        completed
 *                      <li>HASP_INV_HND</li> Invalid input handle
 *                      <li>HASP_INV_FILEID</li> Unrecognized file identifier
 *                      <li>HASP_MEM_RANGE</li> Request exceeds the memory
 *                        range of a Sentinel file
 *                      <li>HASP_DEVICE_ERR</li> Input/Output error in Sentinel
 *                        SL/SL-AdminMode/SL-UserMode secure storage, OR in
 *                        case of a Sentinel HL key, USB communication error
 *                      <li>HASP_SCHAN_ERR</li> Communication error occurred
 *                        in secure channel OR Sentinel HL Firmware too old
 *                        (update to 3.25 or later)
 *                      <li>HASP_BROKEN_SESSION</li> Session has been
 *                        interrupted
 *                      <li>HASP_LOCAL_COMM_ERR</li> Communication error
 *                        between API and local Sentinel License Manager
 *                      <li>HASP_REMOTE_COMM_ERR</li> Communication error
 *                        between local and remote Sentinel License Manager
 *                    </ul>
 *
 * \remark
 * Use the \ref hasp_get_size function to determine the size of the file you
 * want to write.
 *
 * \sa hasp_read()
 * \sa hasp_get_size()
 *
 */
hasp_status_t hasp_write(hasp_handle_t handle,
                hasp_fileid_t fileid,
                hasp_size_t offset,
                hasp_size_t length,
                const void *buffer);

/**
 * \brief Retrieves the byte size of a memory file from a Sentinel protection key.
 *
 * This function is used to determine the file size of a Sentinel
 * memory file.
 *
 * <b>Sentinel Licensing API Usage Notes</b><br>
 * From Sentinel LDK 7.1, Sentinel HL Driverless keys support dynamic memory,
 * the file IDs can be from HASP_FILEID_DYNAMIC_FIRST(0x1) to HASP_FILEID_DYNAMIC_LAST(0xFFBF).
 *
 * \param handle      Handle for the session
 * \param fileid      Identifier for the file that is to be queried.
 * \param size        Pointer to the resulting file size
 *
 * \return            <ul>
 *                      <li>HASP_STATUS_OK</li> Request was successfully
 *                        completed
 *                      <li>HASP_INV_HND</li> Invalid input handle
 *                      <li>HASP_INV_FILEID</li> Unrecognized file identifier
 *                      <li>HASP_DEVICE_ERR</li> Input/Output error in Sentinel
 *                        SL/SL-AdminMode/SL-UserMode secure storage, OR in
 *                        case of a Sentinel HL key, USB communication error
 *                      <li>HASP_BROKEN_SESSION</li> Session has been
 *                        interrupted
 *                      <li>HASP_LOCAL_COMM_ERR</li> Communication error
 *                        between API and local Sentinel License Manager
 *                      <li>HASP_REMOTE_COMM_ERR</li> Communication error
 *                        between local and remote Sentinel License Manager
 *                    </ul>
 *
 * \sa hasp_read()
 * \sa hasp_write()
 *
 */
hasp_status_t hasp_get_size(hasp_handle_t handle,
                hasp_fileid_t fileid,
                hasp_size_t *size);

}
#endif
